#include "Camera.h"

Camera::Camera()
{
}

Camera::Camera(Scalar newMovementSpeed, Scalar newTurningSpeed, Vector newDirection, Vector newEyepoint, Vector newCameraPlane)
: movementSpeed(newMovementSpeed), turningSpeed(newTurningSpeed), direction(newDirection), eyepoint(newEyepoint), cameraPlane(newCameraPlane)
{
}

Camera::~Camera()
{
}

void Camera::MoveForward()
{
	Scalar x, y;
	x = direction.GetX() * movementSpeed;
	y = direction.GetY() * movementSpeed;
	eyepoint.GetX().Add(x);
	eyepoint.GetY().Add(y);
}

void Camera::MoveBackward()
{
	Scalar x, y;
	x = direction.GetX() * movementSpeed;
	y = direction.GetY() * movementSpeed;
	eyepoint.GetX().Substract(x);
	eyepoint.GetY().Substract(y);
}


void Camera::MoveLeft()
{
	Scalar x, y;
	x = direction.GetNormal().GetX() * movementSpeed;
	y = direction.GetNormal().GetY() * movementSpeed;
	eyepoint.GetX().Substract(x);
	eyepoint.GetY().Substract(y);
}

void Camera::MoveRight()
{
	Scalar x, y;
	x = direction.GetNormal().GetX() * movementSpeed;
	y = direction.GetNormal().GetY() * movementSpeed;
	eyepoint.GetX().Add(x);
	eyepoint.GetY().Add(y);
}

void Camera::TurnLeft()
{
	//rotating direction vector
	Scalar oldDirX = direction.GetX();
	direction.SetX(direction.GetX() * (turningSpeed).Cosine() - direction.GetY() * (turningSpeed).Sine());
	direction.SetY(oldDirX * (turningSpeed).Sine() + direction.GetY() * (turningSpeed).Cosine());

	//rotating camera plane vector
	Scalar oldPlaneX = cameraPlane.GetX();
	cameraPlane.SetX(cameraPlane.GetX() * (turningSpeed).Cosine() - cameraPlane.GetY() * (turningSpeed).Sine());
	cameraPlane.SetY(oldPlaneX * (turningSpeed).Sine() + cameraPlane.GetY() * (turningSpeed).Cosine());
}

void Camera::TurnRight()
{
	//rotating direction vector
	Scalar oldDirX = direction.GetX();
	direction.SetX(direction.GetX() * (-turningSpeed).Cosine() - direction.GetY() * (-turningSpeed).Sine());
	direction.SetY(oldDirX * (-turningSpeed).Sine() + direction.GetY() * (-turningSpeed).Cosine());

	//rotating camera plane vector
	Scalar oldPlaneX = cameraPlane.GetX();
	cameraPlane.SetX(cameraPlane.GetX() * (-turningSpeed).Cosine() - cameraPlane.GetY() * (-turningSpeed).Sine());
	cameraPlane.SetY(oldPlaneX * (-turningSpeed).Sine() + cameraPlane.GetY() * (-turningSpeed).Cosine());
}
	
void Camera::SetMovementSpeed(const Scalar& newMovementSpeed)
{
	movementSpeed = newMovementSpeed;
}

void Camera::SetTurningSpeed(const Scalar& newTurningSpeed)
{
	turningSpeed = newTurningSpeed;
}

void Camera::SetEyepoint(const Vector& newEyepoint)
{
	eyepoint = newEyepoint;
}

void Camera::SetDirection(const Vector& newDirection)
{
	direction = newDirection;
}

void Camera::SetCameraPlane(const Vector& newCameraPlane)
{
	cameraPlane = newCameraPlane;
}

const Scalar& Camera::GetMovementSpeed() const
{
	return movementSpeed;
}

const Scalar& Camera::GetTurningSpeed() const
{
	return turningSpeed;
}

const Vector& Camera::GetEyepoint() const
{
	return eyepoint;
}

const Vector& Camera::GetDirection() const
{
	return direction;
}

const Vector& Camera::GetCameraPlane() const
{
	return cameraPlane;
}